package com.xihuanjun.healthcode.config;

import com.xihuanjun.util.json.JsonResult;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value =RuntimeException.class)
    public JsonResult exceptionHandler(Exception e){
        e.printStackTrace();
        System.out.println("全局异常捕获>>>:"+e);
        return new JsonResult().code(444).msg(e.getMessage()).succ(false);
    }

    @ExceptionHandler(value = TooManyResultsException.class)
    public JsonResult tooManyResultsException(TooManyResultsException e){
        return new JsonResult().code(444).msg("查到多条结果").succ(false);
    }
}
